﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Mirkuz.PowerManagement
{
    internal class POWER_BROADCAST
    {
        byte[] buffer;

        public POWER_BROADCAST(byte[] message)
        {
            buffer = message;
        }

        public POWER_BROADCAST(int size)
        {
            buffer = new byte[size];
        }

        public byte[] Data
        {
            get
            {
                return buffer;
            }
        }

        public PowerEventType Message
        {
            get
            {
                return (PowerEventType)BitConverter.ToInt32(buffer, 0);
            }
        }

        public PowerState Flags
        {
            get
            {
                return (PowerState)BitConverter.ToInt32(buffer, 4);
            }
        }

        public int Length
        {
            get
            {
                return BitConverter.ToInt32(buffer, 8);
            }
        }

        public string SystemPowerState
        {
            get
            {
                StringBuilder sb = new StringBuilder(40) ;
                for (int i = 12; i < buffer.Length; i++)
                {
                    if (buffer[i]!=0)
                        sb.Append((char)buffer[i]);
                }
                return sb.ToString();
            }
        }
    }

}
